<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item :label="$t('source')" prop="source">
        <dict-select :options="dict.type.comment_type" v-model="queryParams.source"
                     :placeholder="$t('please-select',[$t('user-type')])"/>
      </el-form-item>
      <el-form-item :label="$t('keyword')" prop="shortVideoContent">
        <el-input
          v-model="queryParams.shortVideoContent"
          :placeholder="$t('please-input',[$t('keyword')])"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('search') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('reset') }}</el-button>
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['video:comments:remove']"
        >{{ $t('delete') }}
        </el-button>
      </el-form-item>
    </el-form>

    <!--    <el-row :gutter="10" class="mb8">-->
    <!--      <el-col :span="1.5">-->
    <!--       -->
    <!--      </el-col>-->
    <!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    <!--    </el-row>-->

    <el-table v-loading="loading" :data="commentsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="id" align="center" prop="id" width="180"/>
      <el-table-column :label="$t('source')" align="center" prop="source"/>
      <el-table-column :label="$t('video.comment.user-name')" align="center" prop="userName" width="180" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.video_audit_type" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column :label="$t('video.comment.short-video-title')" align="center" prop="shortVideoTitle"
                       width="100"/>
      <el-table-column :label="$t('video.comment.short-video-content')" align="center" prop="shortVideoContent"
                       width="250"/>
      <el-table-column :label="$t('create-time')" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('operate')" align="center" width="180">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['video:comments:remove']"
          >{{ $t('delete') }}
          </el-button>
          <el-button
            v-if="scope.row.status == '0'"
            size="mini"
            type="text"
            icon="el-icon-setting"
            @click="handleShow(scope.row.id,1)"
            v-hasPermi="['video:comments:show']"
          >{{ $t('hide') }}
          </el-button>
          <el-button
            v-else
            size="mini"
            type="text"
            icon="el-icon-setting"
            @click="handleShow(scope.row.id,0)"
            v-hasPermi="['video:comments:show']"
          >{{ $t('show') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {delComments, hideComments, listComments, showComments} from "@/api/video/comments";
import DictSelect from "@/components/DictSelect/index.vue";

export default {
  name: "VideoComments",
  components: {DictSelect},
  dicts: ['comment_type','video_audit_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 短视频评论表格数据
      commentsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: this.$yun.v(this.$route.query, 'id'),
        source: null,
        shortVideoContent: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询短视频评论列表 */
    getList() {
      // this.loading = true;
      // this.commentsList = [
      //   {id: 1, source: 0, userName: '111', status: 0},
      //   {id: 2, source: 0, userName: '111', status: 1}
      // ];
      // this.total = 1;
      // this.loading = false;
      // return
      listComments(this.queryParams).then(response => {
        this.commentsList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        parentId: null,
        source: null,
        userId: null,
        userName: null,
        shortVideoId: null,
        shortVideoTitle: null,
        shortVideoContent: null,
        createTime: null,
        status: null,
        deleted: null,
        like: null,
        dislike: null,
        avatar: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id != null ? [row.id] : this.ids;
      this.$modal.confirm(this.$t('delete-or-not')).then(function () {
        return delComments({ids});
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess(this.$t('delete-success'));
      }).catch(() => {
      });
    },
    async handleShow(id, status) {
      const data = {ids: [id], status}
      await (status == '0' ? showComments(data) : hideComments(data))
      this.$modal.msgSuccess(this.$t('operate-success'));
      this.getList();
    }
  }
};
</script>
